package com.template.mongo.utils;

/**
 * Paging info entity
 * 
 */
public class PagingInfo {
	private int segment = 2;
	private int sizePerPage = 5;
	private int currentPage = 1;
	private int totalPage = 0;
	private long totalRecord = 0;
	private String searchValue;

	/**
	 * Setting number of record in a page
	 * 
	 * @param sizePerPage
	 */
	public void setSizePerPage(int sizePerPage) {
		this.sizePerPage = sizePerPage;
	}

	/**
	 * @return number of record in a page
	 */
	public int getSizePerPage() {
		return sizePerPage;
	}

	/**
	 * Setting current page
	 * 
	 * @param currentPage
	 */
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	/**
	 * @return Current page
	 */
	public int getCurrentPage() {
		return currentPage;
	}

	/**
	 * Set total page
	 * 
	 * @param totalPage
	 */
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	/**
	 * @return total page
	 */
	public int getTotalPage() {
		return totalPage;
	}

	/**
	 * @return starting position (0-based index)
	 */
	public int getStartResult() {
		int startPos = 0;

		if (sizePerPage > 0) {
			startPos = sizePerPage * (currentPage - 1);
		}

		return startPos;
	}

	public int getEnd() {
		int end = currentPage + segment;
		if (end > totalPage) {
			end = totalPage;
		}
		return end;
	}

	public int getBegin() {
		int begin = currentPage > segment ? currentPage - segment : 1;
		return begin;
	}

	public String getSearchValue() {
		return searchValue;
	}

	public void setSearchValue(String searchValue) {
		this.searchValue = searchValue;
	}

	public long getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(long totalRecord) {
		this.totalRecord = totalRecord;
	}
}
